package com.bytecollege.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bytecollege.mapper.ArticleMapper;
import com.bytecollege.mapper.CourseCollectMapper;
import com.bytecollege.mapper.CourseMapper;
import com.bytecollege.model.CourseCollect;
import com.bytecollege.service.CourseCollectService;
import com.bytecollege.vo.CourseCollectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: CollectServiceImpl
 * @Description:
 * @Author: Sun
 * @Date: 2022/10/18 21:03
 */
@Service
public class CourseCollectServiceImpl extends ServiceImpl<CourseCollectMapper, CourseCollect> implements CourseCollectService {
    @Autowired
    private CourseCollectMapper courseCollectMapper;
    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private CourseMapper courseMapper;

    public Integer addCollect(CourseCollect courseCollect){
        return courseCollectMapper.add(courseCollect);
    }

    /**
     * 查询某课程的收藏量
     * @param courseId
     * @return
     */
    public Integer getCollectNumByCourseId(Integer courseId){
        return courseCollectMapper.getCollectNumByCourseId(courseId);
    }

    /**
     * 获取课程的收藏状态
     * @param courseId
     * @param userId
     * @return 1：未收藏
     *         0：已收藏
     */
    public Integer getCollectStatus(Integer courseId,Integer userId){
        CourseCollect courseCollect = courseCollectMapper.getOne(courseId, userId);
        if (courseCollect == null){
            return 1;
        }
        return 0;
    }

    /**
     * 课程收藏
     * @param page
     * @param userId
     * @return
     */
    public List<CourseCollectVo> getCourseCollect(Page<CourseCollectVo> page, Integer userId){
         return courseCollectMapper.getCourseCollect(page,userId);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    public int delCourseCollectById(Integer id){
        return courseCollectMapper.del(id);
    }

}